Skip to content

feat(ramps-controller): share provider/quote/error helpers with consumers#9409

Draft
saustrie-consensys wants to merge 1 commit into
mainfrom
saustrie/ramps-controller-ui-logic
Draft

feat(ramps-controller): share provider/quote/error helpers with consumers#9409
saustrie-consensys wants to merge 1 commit into
mainfrom
saustrie/ramps-controller-ui-logic

Conversation

@saustrie-consensys

Copy link
Copy Markdown
Contributor

Explanation

Headless Buy provider expansion in metamask-mobile re-derived logic that RampsController already owns privately: the CAIP-19 provider-serves-asset match, the scope-aware region/availability gate, the in-app-vs-external quote classification, and error-shape normalization. That duplication meant the UI gate could drift from the controller's own provider selection.

This PR lifts that logic into pure, tested, exported helpers so consumers can share it instead of re-implementing it, and rewires the controller to consume the same helpers so the shared surface stays behaviourally identical to the controller's internal selection:

  • providerAvailability: providerServesAsset, getProvidersServingAsset, regionHasProviderForAsset, isFiatDepositAvailable. RampsController.#getSupportingProvidersForRegion now uses the shared matcher.
  • quoteClassification: isExternalBrowserQuote, isCustomActionQuote, isInAppOnlyQuote. RampsController.#pickInAppQuote now uses these for its in-app filter.
  • errorNormalization: getErrorMessage, extractExplicitTypedError, normalizeToTypedError (+ TypedError<Code>). Consumers keep their own error-code taxonomy while sharing the extraction; the deliberately host-specific bits (deeplink schemes, redirect URLs, session lifecycle, error taxonomy values) stay in the consumer.

No behaviour change for existing consumers: the helpers are additive, and the controller's refactored call sites are covered by the existing suite (all 579 package tests pass, plus 42 new helper tests).

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Made with Cursor

…mers

Expose the provider-availability, quote-classification, and error-normalization
logic the controller uses internally as pure, tested helpers so headless-buy
consumers (e.g. metamask-mobile) can share it instead of re-deriving it:

- providerServesAsset, getProvidersServingAsset, regionHasProviderForAsset,
  isFiatDepositAvailable
- isExternalBrowserQuote, isCustomActionQuote, isInAppOnlyQuote
- getErrorMessage, extractExplicitTypedError, normalizeToTypedError (+ TypedError)

RampsController now derives its own region asset-matching and quote filtering
from these helpers so the shared surface stays behaviourally identical to the
controller's selection.
@saustrie-consensys saustrie-consensys force-pushed the saustrie/ramps-controller-ui-logic branch from 75ef2c5 to 685219b Compare July 7, 2026 14:59
@saustrie-consensys

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.3-preview-685219bbf
@metamask-previews/accounts-controller@39.0.4-preview-685219bbf
@metamask-previews/address-book-controller@7.1.2-preview-685219bbf
@metamask-previews/ai-controllers@0.7.0-preview-685219bbf
@metamask-previews/analytics-controller@1.2.1-preview-685219bbf
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-685219bbf
@metamask-previews/announcement-controller@8.1.0-preview-685219bbf
@metamask-previews/app-metadata-controller@2.0.1-preview-685219bbf
@metamask-previews/approval-controller@9.0.2-preview-685219bbf
@metamask-previews/assets-controller@10.0.1-preview-685219bbf
@metamask-previews/assets-controllers@109.3.0-preview-685219bbf
@metamask-previews/authenticated-user-storage@3.0.0-preview-685219bbf
@metamask-previews/base-controller@9.1.0-preview-685219bbf
@metamask-previews/base-data-service@0.1.3-preview-685219bbf
@metamask-previews/bitcoin-regtest-up@1.0.0-preview-685219bbf
@metamask-previews/bridge-controller@77.3.2-preview-685219bbf
@metamask-previews/bridge-status-controller@74.0.2-preview-685219bbf
@metamask-previews/build-utils@3.0.4-preview-685219bbf
@metamask-previews/chain-agnostic-permission@1.7.0-preview-685219bbf
@metamask-previews/chomp-api-service@3.1.0-preview-685219bbf
@metamask-previews/claims-controller@0.5.3-preview-685219bbf
@metamask-previews/client-controller@1.0.1-preview-685219bbf
@metamask-previews/client-utils@0.0.0-preview-685219bbf
@metamask-previews/compliance-controller@2.1.0-preview-685219bbf
@metamask-previews/composable-controller@12.0.1-preview-685219bbf
@metamask-previews/config-registry-controller@0.4.1-preview-685219bbf
@metamask-previews/connectivity-controller@0.2.0-preview-685219bbf
@metamask-previews/controller-utils@12.3.0-preview-685219bbf
@metamask-previews/core-backend@6.5.0-preview-685219bbf
@metamask-previews/delegation-controller@3.0.2-preview-685219bbf
@metamask-previews/earn-controller@12.2.2-preview-685219bbf
@metamask-previews/eip-5792-middleware@3.0.4-preview-685219bbf
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-685219bbf
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-685219bbf
@metamask-previews/ens-controller@19.1.5-preview-685219bbf
@metamask-previews/eth-block-tracker@15.0.1-preview-685219bbf
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-685219bbf
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-685219bbf
@metamask-previews/foundryup@1.0.1-preview-685219bbf
@metamask-previews/gas-fee-controller@26.2.4-preview-685219bbf
@metamask-previews/gator-permissions-controller@4.2.2-preview-685219bbf
@metamask-previews/geolocation-controller@0.1.3-preview-685219bbf
@metamask-previews/java-tron-up@1.0.0-preview-685219bbf
@metamask-previews/json-rpc-engine@10.5.0-preview-685219bbf
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-685219bbf
@metamask-previews/keyring-controller@27.1.0-preview-685219bbf
@metamask-previews/local-node-utils@1.0.0-preview-685219bbf
@metamask-previews/logging-controller@8.0.2-preview-685219bbf
@metamask-previews/message-manager@14.1.2-preview-685219bbf
@metamask-previews/messenger@2.0.0-preview-685219bbf
@metamask-previews/messenger-cli@0.2.0-preview-685219bbf
@metamask-previews/money-account-api-data-service@0.0.0-preview-685219bbf
@metamask-previews/money-account-balance-service@2.1.2-preview-685219bbf
@metamask-previews/money-account-controller@0.3.3-preview-685219bbf
@metamask-previews/money-account-upgrade-controller@2.2.1-preview-685219bbf
@metamask-previews/multichain-account-service@11.1.0-preview-685219bbf
@metamask-previews/multichain-api-middleware@4.0.1-preview-685219bbf
@metamask-previews/multichain-network-controller@3.2.1-preview-685219bbf
@metamask-previews/multichain-transactions-controller@7.1.1-preview-685219bbf
@metamask-previews/name-controller@9.1.2-preview-685219bbf
@metamask-previews/network-controller@34.0.0-preview-685219bbf
@metamask-previews/network-enablement-controller@5.4.1-preview-685219bbf
@metamask-previews/notification-services-controller@25.0.0-preview-685219bbf
@metamask-previews/passkey-controller@2.0.1-preview-685219bbf
@metamask-previews/permission-controller@13.1.1-preview-685219bbf
@metamask-previews/permission-log-controller@5.1.0-preview-685219bbf
@metamask-previews/perps-controller@9.2.1-preview-685219bbf
@metamask-previews/phishing-controller@17.2.0-preview-685219bbf
@metamask-previews/platform-api-docs@0.0.0-preview-685219bbf
@metamask-previews/polling-controller@16.0.8-preview-685219bbf
@metamask-previews/preferences-controller@23.1.0-preview-685219bbf
@metamask-previews/profile-metrics-controller@4.0.1-preview-685219bbf
@metamask-previews/profile-sync-controller@28.2.0-preview-685219bbf
@metamask-previews/ramps-controller@15.1.0-preview-685219bbf
@metamask-previews/rate-limit-controller@7.0.1-preview-685219bbf
@metamask-previews/react-data-query@0.2.1-preview-685219bbf
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-685219bbf
@metamask-previews/sample-controllers@5.0.3-preview-685219bbf
@metamask-previews/seedless-onboarding-controller@10.0.3-preview-685219bbf
@metamask-previews/selected-network-controller@26.1.5-preview-685219bbf
@metamask-previews/shield-controller@5.1.2-preview-685219bbf
@metamask-previews/signature-controller@39.2.7-preview-685219bbf
@metamask-previews/smart-transactions-controller@24.2.4-preview-685219bbf
@metamask-previews/snap-account-service@1.0.0-preview-685219bbf
@metamask-previews/social-controllers@2.3.1-preview-685219bbf
@metamask-previews/solana-test-validator-up@1.0.0-preview-685219bbf
@metamask-previews/stellar-quickstart-up@0.0.0-preview-685219bbf
@metamask-previews/storage-service@1.0.2-preview-685219bbf
@metamask-previews/subscription-controller@6.2.0-preview-685219bbf
@metamask-previews/transaction-controller@68.2.2-preview-685219bbf
@metamask-previews/transaction-pay-controller@23.17.4-preview-685219bbf
@metamask-previews/user-operation-controller@41.2.6-preview-685219bbf
@metamask-previews/wallet@7.0.0-preview-685219bbf
@metamask-previews/wallet-cli@0.0.0-preview-685219bbf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant